﻿using System.Collections.Generic;
using System.Drawing;
using Ants.SimpleDistributionProblem.DTO;

namespace Ants.SimpleDistributionProblem
{
    /// <summary>
    /// Class representing route map.
    /// </summary>
    public class RouteMap
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="RouteMap" /> class.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="initialPheromoneAmount">The initial pheromone amount.</param>
        public RouteMap(Data data, double initialPheromoneAmount)
        {
            this.RouteParts = new List<RoutePart>();
            List<Point> cities = new List<Point>(data.Cities);
            this.StartingPoint = cities[0];
            while (cities.Count != 0)
            {
                Point city = cities[0];
                cities.Remove(city);
                foreach (Point secondCity in cities)
                {
                    this.RouteParts.Add(new RoutePart()
                    {
                        PointA = city,
                        PointB = secondCity,
                        PheromoneAmount = initialPheromoneAmount
                    });
                }
            }
        }

        /// <summary>
        /// Gets or sets the route parts.
        /// </summary>
        /// <value>
        /// The route parts.
        /// </value>
        public List<RoutePart> RouteParts { get; set; }

        /// <summary>
        /// Gets the starting point.
        /// </summary>
        /// <value>
        /// The starting point.
        /// </value>
        public Point StartingPoint { get; private set; }

        /// <summary>
        /// Adds the pheromone.
        /// </summary>
        /// <param name="ants">The ants.</param>
        /// <param name="qParameter">The q parameter.</param>
        public void AddPheromone(List<Ant> ants, double qParameter)
        {
            foreach (Ant ant in ants)
            {
                for (int i = 1; i < ant.Solution.Route.Count; i++)
                {
                }
            }
        }

        /// <summary>
        /// Evaporates the pheromone.
        /// </summary>
        /// <param name="coefficientOfEvaporation">The coefficient of evaporation.</param>
        public void EvaporatePheromone(double coefficientOfEvaporation)
        {
            foreach (RoutePart part in this.RouteParts)
            {
                part.PheromoneAmount *= (1 - coefficientOfEvaporation);
            }
        }
    }
}